<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
		<link href="../resources/css/team.css" rel="stylesheet" type="text/css">
		<!-- including external jquery library to make js scripting easier -->
		<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
		<title>My Teams</title>
	</head>
	<body>
		<?php
		//including navigation menu 
		include '../view/header.php';?>
		<div style="clear:both;"></div>
		<div class="mainbox" > <p align="center" > ** My Teams **</p>
			<select id="teamSelector" name="teamSelector">
				<option value="none" selected="selected">Select Your Team</option>
				<?php foreach($teams as $t){?>
				<option value="<?php echo $t->getName();?>"><?php echo $t->getType();?></option>		 
				<?php } ?>
			</select>
			<?php   
				//is captain is used to determine weather the current user can add players or just view
				$isCaptain="false";
				//go through the teams that this user plays on and construct roster
			    foreach($teams as $t){
					$members = $t->getMembers();
					if($_SESSION['user']->getStudentId() == $t->getCaptain()->getStudentId()){
						$isCaptain = "true";
					} else {
				        $isCaptain = "false";
					}
				?>
				<div id="<?php echo $t->getName();?>" class="team">
					<h1><?php echo $t->getName();?></h1>
					<?php if($isCaptain=="true") {?>
						<form action="../model/team.php" method="post">
							<div>
								<input id="addplayer" name="uwid" type="text" value="enter uw id of player to add"/>
								<input name="teamid" type="hidden" value="<?php echo $t->getId();?>"/>
								<input id="submit" name="submit" type="submit" value="Add Player"/>
							</div>
						</form>
					<?php }?>
					<div align="center" class="roster">
						<div class="lastName">Last Name</div>
						<div class="firstName">First Name</div>
						<?php 
						//display members on the team and mark captain
						foreach ($members as $m) {?>
							<div class="lastName">
								<?php if($m->getStudentId() == $t->getCaptain()->getStudentId() ) {echo '[C] '; } echo $m->getLastName();?>
							</div>
							<div class="firstName"><?php echo $m->getFirstName(); ?></div>
						<?php }?>
					</div>
				</div>
			<?php } ?>
			
		</div>
		<script type="text/javascript">
			//when page is ready hide all team divs and wire the drop down so onchange it displays appripriate team div containg roster info
			$(document).ready(function(){
				$(".team").css("display","none");
				<?php if(isset($success)){?>
					alert('Player has been added successfully.');
				<?php }?>
				$('#teamSelector').change(function(){
					$(".team").css("display","none");
					var div_id = $(this).val();
					$('#'+div_id).show(); 
				});
			});
		</script>
	</body>
</html>
